﻿// -----------------------------------------------------------------------
// <copyright file="DeliveryMapping.cs" company="DosTex"/>
// -----------------------------------------------------------------------

namespace DosTexPrj.Implement.NHibernate.Mapping
{
    using DosTexPrj.Core.Models;
    using FluentNHibernate.Mapping;

    /// <summary>
    /// TODO: Mapping Delivery class
    /// </summary>
    public class DeliveryMapping : ClassMap<Delivery>
    {
        public DeliveryMapping()
        {
            Table("Deliveries");
            Id(x => x.Id, "DeliveryID").UnsavedValue(0).GeneratedBy.Identity();
            Map(x => x.DeliveryAddress).Not.Nullable().Length(300);
            Map(x => x.DeliveryDate).Not.Nullable();
            References<Order>(x => x.BelongToOrder).Column("OrderID").Not.LazyLoad();
            HasMany<DeliveryDetail>(x => x.Details).KeyColumn("DeliveryID").Cascade.AllDeleteOrphan()
                                                   .Not.LazyLoad().AsBag();
        }
    }
}